<?php

namespace App\Store\Models\Order;

use App\Common\Services\Common;
use App\Store\Models\Basic\GoodsCategory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use App\Common\Services\Store\Common as StoreCommon;
use App\Store\Models\Account\SiteStore;
use App\Store\Models\Member\Member;
use App\Store\Models\Account\Account;
use App\Store\Models\Sysset\Classesset;

class OrderRecoveryGoods extends Model
{
    protected $table = 'site_order_recovery_goods';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];

    public static function getList($request)
    {
        $ids = $request['ids'];
        $ids = is_array($ids) ? $ids : (is_array(json_decode($ids, true)) ? json_decode($ids, true) : []);

        $query = self::with(['storeinfo', 'goods_category', 'recovery_info'])->whereIn('p_id', $ids)->where('is_del', 1);
        $list = $query->get()->toArray();
        return ['list' => $list];
    }

    public function storeinfo()
    {
        return $this->hasOne(SiteStore::class, 'id', 'store_id')->select('id', 'store_name','brand_url','contact_name','contact_phone','staff_name','address_area');
    }

    public function goods_category()
    {
        return $this->hasOne(GoodsCategory::class, 'id', 'goods_category_id')->select('id', 'category_name');
    }

    public function recovery_info()
    {
        return $this->hasOne(OrderRecovery::class, 'id', 'pid')->select('id', 'order_sn', 'total_money', 'pay_type_name');
    }

    public function memberinfo()
    {
        return $this->hasOne(Member::class, 'id', 'mem_id')->where('is_del',1);
    }
    public function shoppingaccountinfo1(){

        return $this->hasOne(Account::class, 'id', 'shopping_account_id1');
    }
    public function shoppingaccountinfo2(){

        return $this->hasOne(Account::class, 'id', 'shopping_account_id2');
    }
    public function classessetinfo(){

        return $this->hasOne(Classesset::class, 'id', 'classesset_id');

    }

    public function orderinfo(){

        return $this->hasOne(OrderRecovery::class, 'id', 'pid');
    }

    public function salseordergoods(){

        return $this->hasOne(OrderSalesGoods::class, 'id', 'sales_goods_id')->select('id','goodsinfo');
    }
}
